package com.imooc.security.config;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import com.imooc.security.order.OrderInfo;

/**
 * @author wangyouliang
 */
public class Test {

	public static void main(String[] args) throws InterruptedException {
		RestTemplate restTemplate = new RestTemplate();
		
		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
		headers.set("Authorization", "bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODg5NDIwNTUsInVzZXJfbmFtZSI6Impvam8iLCJhdXRob3JpdGllcyI6WyJST0xFX0FETUlOIl0sImp0aSI6IjA1OTgyYTUyLWE4OTItNGNkOC1iZGVjLTgyMDVhMWMxOTFkNyIsImNsaWVudF9pZCI6ImFkbWluIiwic2NvcGUiOlsicmVhZCIsIndyaXRlIl19.sXaAdUcX6JZ5gA6cH90fuLeodLL4lH19RZXtYLN0SSLk7Yug55zzYbbOcv0G169UousjSjMaDRBACMGNaYrhOcNIODTmgSNUvO2sTVGj6K_f66-rh1VVCY4o-7ssJoyqnP--a9eLhJYYPBxGeZxl04n5RC7TTEWTzDdntkW2z7ZjkJ7zvrOuVEOyLb2oBBEuMjtSin3zsKT6LfZm6UxQ_YyXG3fF_6C-yRtOk4yZcuxIBmSXtbPyF485c4WowpMeyMkI-N2923mz_vdt6jzNBZ0UWo9Bne2jxBGLzcwTv3B_ImgumNFQiYuNaalvRsQfL_-x0_UkO_2BRpgnMU-raQ");

		OrderInfo info = new OrderInfo();
		info.setProductId(123L);
		
		HttpEntity<OrderInfo> entity = new HttpEntity<OrderInfo>(info, headers);
		
		while (true) {
			try {
				restTemplate.exchange("http://order.imooc.com:9082/orders", HttpMethod.POST, entity, String.class);
			} catch (Exception e) {
			}
//			Thread.sleep(100);
		}
	}

}
